package cn.wolfcode.crm.web.controller;

import cn.wolfcode.crm.domain.CustomerTransfer;
import cn.wolfcode.crm.page.PageResult;
import cn.wolfcode.crm.query.CustomerTransferQueryObject;
import cn.wolfcode.crm.service.ICustomerTransferService;
import cn.wolfcode.crm.util.JsonResult;
import cn.wolfcode.crm.util.PermissionName;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("customerTransfer")
public class CustomerTransferController {

    @Autowired
    private ICustomerTransferService customerTransferService;

    @RequestMapping("")
    @RequiresPermissions("customerTransfer:index")
    @PermissionName("客户转移列记录")
    public String index() {
        return "customer_transfer";
    }


    @RequestMapping("list")
    @ResponseBody
    public PageResult list(CustomerTransferQueryObject qo) {

        PageResult result = customerTransferService.query(qo);

        return result;
    }

    @RequestMapping("trans")
    @RequiresPermissions("customerTransfer:trans")
    @PermissionName("转移库户记录保存")
    @ResponseBody
    public JsonResult trans(CustomerTransfer customerTransfer) {
        JsonResult result = new JsonResult();
        try{
            customerTransferService.trans(customerTransfer);
            result.setMessage("保存成功");
        }catch (Exception e){
            e.printStackTrace();
            result.mark("保存失败");
        }

        return result;
    }

}